package com.ruoyi.system.api.factory;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.system.api.RemoteLoginService;
import com.ruoyi.system.api.form.LoginBody;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;

@Component
public class RemoteLoginFallbackFactory implements FallbackFactory<RemoteLoginService> {
    private static final Logger log = LoggerFactory.getLogger(RemoteLoginFallbackFactory.class);


    @Override
    public RemoteLoginService create(Throwable cause) {
        log.error("登录服务调用失败:{}", cause.getMessage());
        return new RemoteLoginService() {


            @Override
            public R<?> login(LoginBody form) {
                return R.fail("登陆失败"+cause.getMessage());
            }

            @Override
            public R<?> logout(HttpServletRequest request) {
                return R.fail("注销失败"+cause.getMessage());
            }

            @Override
            public R<?> refresh(HttpServletRequest request) {
                return R.fail("刷新失败"+ cause.getMessage());
            }

            @Override
            public R<?> register(LoginBody registerBody) {
                return R.fail("注册失败" + cause.getMessage());
            }
        };
    }
}
